package com.example.xd.tuiliu_test;

import android.Manifest;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import com.example.xd.tuiliu_test.rtmp.PushStreamActivity;
import com.example.xd.tuiliu_test.rtp.RtpPushActivity;
import com.example.xd.tuiliu_test.videoplayer.sample.Sample3Activity;
import com.example.xd.tuiliu_test.videoplayer.sample.Sample4Activity;

import java.util.List;

import pub.devrel.easypermissions.EasyPermissions;

public class MainActivity extends AppCompatActivity implements View.OnClickListener, EasyPermissions.PermissionCallbacks {
    String[] permissions = {Manifest.permission.CAMERA,
            Manifest.permission.ACCESS_NETWORK_STATE,
            Manifest.permission.CAPTURE_AUDIO_OUTPUT,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.RECORD_AUDIO};


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        if (EasyPermissions.hasPermissions(MainActivity.this, permissions)) {
            setClick();
        } else {
            EasyPermissions.requestPermissions(MainActivity.this, "权限申请", 1, permissions);
        }

    }

    private void setClick() {
        findViewById(R.id.btn_push).setOnClickListener(this);
        findViewById(R.id.btn_pull).setOnClickListener(this);
        findViewById(R.id.btn_rtp_push).setOnClickListener(this);
        findViewById(R.id.btn_rtp_pull).setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_pull:
                startActivity(new Intent(this, Sample3Activity.class));
                break;
            case R.id.btn_push:
                startActivity(new Intent(MainActivity.this, PushStreamActivity.class));
                break;
            case R.id.btn_rtp_push:
                startActivity(new Intent(MainActivity.this, RtpPushActivity.class));
                break;
            case R.id.btn_rtp_pull:
                startActivity(new Intent(MainActivity.this, RtpPushActivity.class));
                break;
        }

    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
        EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
    }

    @Override
    public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
        setClick();

    }

    @Override
    public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {

    }
}
